﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ElCharro01.Models;

namespace ElCharro01.Areas.Admin.Controllers
{
    //[Authorize(Roles = "Administrator")]
    public class ClothingTypeController : Controller
    {
        private Entities db = new Entities();

        //
        // GET: /Admin/ClothingType/

        public ViewResult Index()
        {
            return View(db.ClothingTypeSet.ToList());
        }

        //
        // GET: /Admin/ClothingType/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /Admin/ClothingType/Create

        [HttpPost]
        public ActionResult Create(ClothingType clothingtype)
        {
            if (ModelState.IsValid)
            {
                db.ClothingTypeSet.AddObject(clothingtype);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(clothingtype);
        }

        //
        // GET: /Admin/ClothingType/Edit/5

        public ActionResult Edit(int id)
        {
            ClothingType clothingtype = db.ClothingTypeSet.Single(c => c.ID == id);
            return View(clothingtype);
        }

        //
        // POST: /Admin/ClothingType/Edit/5

        [HttpPost]
        public ActionResult Edit(ClothingType clothingtype)
        {
            if (ModelState.IsValid)
            {
                db.ClothingTypeSet.Attach(clothingtype);
                db.ObjectStateManager.ChangeObjectState(clothingtype, EntityState.Modified);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(clothingtype);
        }

        //
        // GET: /Admin/ClothingType/Delete/5

        public ActionResult Delete(int id)
        {
            ClothingType clothingtype = db.ClothingTypeSet.Single(c => c.ID == id);
            return View(clothingtype);
        }

        //
        // POST: /Admin/ClothingType/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            ClothingType clothingtype = db.ClothingTypeSet.Single(c => c.ID == id);
            db.ClothingTypeSet.DeleteObject(clothingtype);
            db.SaveChanges();
            return RedirectToAction("Index");
        }
        
        // visualizza i clothing type nel menu di navigazione
        public ActionResult ClothingTypeMenu()
        {
            return View(db.ClothingTypeSet.ToList());
        }


        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}